import * as r from '../base_rule';


export const ForbidInnerHTMLInComponent = r.pattern(
  {
    name: "ForbidInnerHTMLInComponent",
    description: "Detects usage of innerHTML in @Component decorated classes in ArkTS. TODO 还没做完",
    severity: 'high',
    tags: ['security', 'arkts', 'xss'],
  },
  (q) => q
    .from(f => f.withData(v => v.stream().any(s => {
      if (!(s instanceof r.AssignStmt)) return false;
      return true
    }
    )).as("Source"))

    .from(f => f.withPredicate(s => {
      if (!(s instanceof r.AssignStmt)) return false;
      return true
    }).as("Sink"))

    .exists(f => f.configure({
      flow: new r.HamiltonFlow(),
      strategy: new r.DfgTraverse()
    }).source("Source").sink("Sink").as("DataFlow"), () => new r.DataFlow())
    .select("Source", "Sink", "DataFlow")
)
